package dao;

import java.util.List;

import entity.User;

public class UserDao {

	public List<User> select(String where) {
		return DbHepler.executeQuery("select * from user " +where, User.class);
	}
	
	public List<User> login(String name,String pass) {
		return DbHepler.executeQuery("select * from user "
				+ " where name='"+name+"' and pass='"+pass+"'", User.class);
	}
	
	public int insert(User model) {
		return DbHepler.executeUpdate("insert into user (name,pass,tel,power,status) values(?,?,?,?,?)", 
				model.getName(),
				model.getPass(),
				model.getTel(),
				model.getPower(),
				model.getStatus());
	}
	
	public int update(User model) {
		return DbHepler.executeUpdate("update user set name=?,pass=?,tel=?,power=?,status=? where id=?",
				model.getName(),
				model.getPass(),
				model.getTel(),
				model.getPower(),
				model.getStatus(), 
				model.getId());
	}
	
	public int updatepass(User model) {
		return DbHepler.executeUpdate("update user set pass=? where id=?",model.getPass(), model.getId());
	}
	
	public int delete(int id) {
		return DbHepler.executeUpdate("delete from user where id=?", id);
	}
	
	public User getbyid(int id) {
		List<User> list=DbHepler.executeQuery("select * from user where id=?", User.class,id);
		return list.get(0);
	}
	
}
